import 'package:flutter/material.dart';
import 'package:hm_show_flutter/style/style.dart';

typedef OnRetry();

///空数据view
class EmptyView extends StatefulWidget {
  final String hintText;
  final OnRetry onRetry;
  final double topPadding;

  EmptyView({this.hintText,this.onRetry,this.topPadding = 100});

  @override
  _EmptyViewState createState() => _EmptyViewState();
}

class _EmptyViewState extends State<EmptyView> {
  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        return GestureDetector(
          onTap: widget.onRetry == null?null:widget.onRetry,
          child: Container(
            color: Colors.grey[50],
            alignment: Alignment.topCenter,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Padding(padding: EdgeInsets.only(top: widget.topPadding)),
                Image.asset(
                  "images/ic_state_empty_content.png",
                  width: 160,
                  height: 200,
                ),
                Text(
                  "暂无数据",
                  style: TextStyle(
                    color: AppColors.grey,
                    fontSize: 12
                  ),
                  textAlign: TextAlign.center,
                ),
                Padding(padding: EdgeInsets.only(top: 10)),
                widget.onRetry == null?Container():Text(
                  "点击重新加载...",
                  style: TextStyle(
                    color: AppColors.grey,
                    fontSize: 12
                  ),
                  textAlign: TextAlign.center,
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
